package com.hh.service.dao;

import com.hh.common.model.product.StoreProduct;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hh.common.response.IndexProductResponse;
import com.hh.common.response.pagemanagement.ProductResponse;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 商品表 Mapper 接口
 * +----------------------------------------------------------------------
 * | hh [ hh赋能开发者，助力企业发展 ]
 * +----------------------------------------------------------------------
 * | Copyright (c) 2016~2022 https://www.hh.com All rights reserved.
 * +----------------------------------------------------------------------
 * | Licensed hh并不是自由软件，未经许可不能去掉hh相关版权
 * +----------------------------------------------------------------------
 * | Author: hh Team <admin@hh.com>
 * +----------------------------------------------------------------------
 */
public interface StoreProductDao extends BaseMapper<StoreProduct> {

    @Select("select count(*) from eb_store_product where id = #{linkUrl} and is_recycle = 0 and is_del=0 and stock > 0 and is_show=1")
    int selectCountByBanner(@Param("linkUrl") Integer linkUrl);

    @Select("select id,image,price,store_name,ot_price,sales,ficti from eb_store_product where is_best = 1 and is_recycle = 0 and is_del=0 and is_show=1 order by sort desc,id desc limit 0,10")
    List<ProductResponse> selectSuperiorProductsRecommendList();

    @Select("select id,image,price,store_name,ot_price,sales,ficti from eb_store_product where is_new = 1 and is_recycle = 0 and is_del=0 and is_show=1 order by sort desc,id desc limit 0,20")
    List<ProductResponse> selectRecommendedForYouList();

    @Select("select id,image,price,store_name,ot_price,sales,ficti from eb_store_product where is_hot = 1 and is_recycle = 0 and is_del=0 and is_show=1 order by sort desc,id desc limit 0,20")
    List<ProductResponse> selectHotProductsList();

    @Select("select id,image,price,store_name,ot_price,sales,ficti from eb_store_product where is_benefit = 1 and is_recycle = 0 and is_del=0 and is_show=1 order by sort desc,id desc limit 0,20")
    List<ProductResponse> selectSpecialOfferZoneList();

    @Update("update eb_store_product set stock = stock+#{payNum} where id = #{productId}")
    boolean addInventory(@Param("productId") Integer productId, @Param("payNum") Integer payNum);

    @Select("select id,image,price,store_name,ot_price,sales,ficti from eb_store_product where is_best = 1 and is_recycle = 0 and is_del=0 and is_show=1 order by sort desc,id desc")
    List<IndexProductResponse> getRecommendSuperiorproductsrecommendListPage();

    @Select("select id,image,price,store_name,ot_price,sales,ficti from eb_store_product where is_new = 1 and is_recycle = 0 and is_del=0 and is_show=1 order by sort desc,id desc")
    List<IndexProductResponse> getRecommendforyouListPage();

    @Select("select id,image,price,store_name,ot_price,sales,ficti from eb_store_product where is_hot = 1 and is_recycle = 0 and is_del=0 and is_show=1 order by sort desc,id desc")
    List<IndexProductResponse> getHotproductsListPage();

    @Select("select id,image,price,store_name,ot_price,sales,ficti from eb_store_product where is_benefit = 1 and is_recycle = 0 and is_del=0 and is_show=1 order by sort desc,id desc")
    List<IndexProductResponse> getRecommendSpecialofferZoneListPage();
}
